<?php
namespace Admin\Model;

use Think\Model;

class ThemeTplModel extends Model {

	protected $_validate = array(
			array('file', 'require', '菜单名必须输入', self::MUST_VALIDATE),
			array('file','','文件已经存在', self::EXISTS_VALIDATE, 'unique'),
	);
	
    protected function _after_insert($data, $options) {
		$this->saveTplAuth($data, 'insert');
    }
    
    protected function _after_update($data, $options) {
    	$this->saveTplAuth($data, 'update');
    }
    
    private function saveTplAuth( $data, $oprate ) {
    	$tplId = $data['id'];
    	$theme = I("theme", 0);
    	if( $theme and $tplId ) {
    		if( $oprate == 'update')
	    		M("ThemeTplAuth")->where("tpl_id=%d", $tplId)->save(array(
	    			'theme' => $theme,
	    		));
    		else 
    			M("ThemeTplAuth")->add(array(
    				'tpl_id' => $tplId,
    				'theme' => $theme,
    			));
    	}
    }
	
}